package logic

import (
	"context"
	"ewaimai/waimairpc/models"

	"ewaimai/waimairpc/internal/svc"
	"ewaimai/waimairpc/waimairpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsPeopleListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsPeopleListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsPeopleListLogic {
	return &GoodsPeopleListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsPeopleListLogic) GoodsPeopleList(in *waimairpc.GoodsPeopleListRequest) (*waimairpc.GoodsPeopleListResponse, error) {
	// todo: add your logic here and delete this line
	var g []models.GoodsPeople
	models.DB.Debug().Order("num desc").Where("goods_people.name,goods_people.address,goods_people.goods_num").Find(&g)
	var peoplelist []*waimairpc.GoodsPeopleList
	for _, goods := range g {
		list := waimairpc.GoodsPeopleList{
			Name:    goods.Name,
			Address: goods.Address,
			Num:     int64(goods.Num),
			Status:  1,
		}
		peoplelist = append(peoplelist, &list)
	}
	return &waimairpc.GoodsPeopleListResponse{
		List: peoplelist,
	}, nil
}
